package com.vids.controller;

import com.vids.hikcam.HIKCamAlarm;
import com.vids.mapper.ApeMapper;
import com.vids.model.entity.Ape;
import com.vids.service.IApeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class Test {
    @Resource
    private ApeMapper apeMapper;

    static {
        HIKCamAlarm.sdk_net_dvr_init();
    }

    public void getSDK() {
        List<Ape> resultList = apeMapper.findAll();
            for (Ape ape : resultList) {
//                如果是海康的摄像头
//                公共
                if (isHikCamera(ape)&&HIKCamAlarm.sdk_net_dvr_init()) {

                    int userId = HIKCamAlarm.startApeAlarm(ape.getIPAddr(), ape.getPort(),
                            ape.getUserId(), ape.getPassword());
                    if (userId >= 0) {
                        log.info("getSDK成功 -> {}", userId);
                    } else {
                        log.info("getSDK失败 -> {}", userId);
                        HIKCamAlarm.stopApeAlarm(userId);
                    }
                }



            }



//        try {
//            Thread.sleep(60000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//        log.info("SDK正常调用完毕");
//        HIKCamAlarm.stopApeAlarm(userId);
//        HIKCamAlarm.sdk_net_dvr_cleanup();


    }
    public boolean isHikCamera(Ape ape)
    {
        if (ape.getModel() == null) {
            log.error("接入相机的厂家型号有问题" +ape.getApeID());
            return false;
        }
        if (ape.getMakers() == null) {
            return ape.getModel().contains("DS-2C")||ape.getModel().contains("2CD7");
        }else {
            return ape.getMakers().equals("1");
        }

    }
}
